﻿using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace WPFExcelReport
{

    using zl_u8 = Byte;
    using zl_u16 = System.UInt16;
    using zl_u32 = System.UInt32;
    using zl_s8 = SByte;
    using zl_s16 = System.Int16;
    using zl_s32 = System.Int32;
    using zl_bool = System.Int32;
    using zl_boolean = System.UInt32;
    using zl_char = System.SByte;
    using zl_int = System.Int32;
    using IP_ADDR = System.UInt32;
    using ZLDevHandler = System.UInt32;
    /*
     using zl_u8=unsigned char; 
         using zl_u8=unsigned char; 
         using zl_u32=int; 

     typedef unsigned char zl_u8; typedef unsigned short zl_u16; 
     typedef unsigned int zl_u32;
     typedef char zl_s8; typedef short zl_s16; typedef int zl_s32;
     typedef unsigned int zl_bool; typedef unsigned int zl_boolean;
     typedef char zl_char; typedef void zl_void; typedef int zl_int;
     typedef zl_u32   IP_ADDR;
         typedef zl_u32   ZLDevHandler; */
#pragma pack(4)
    //pack(4)
    /* 参数结构体 */
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public struct SDevParam
    {

        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
        public char[] DevName;
        public zl_u8 IPMode;

        public IP_ADDR LocalIP;
        public IP_ADDR NetMask;
        public IP_ADDR GateWay;
        public IP_ADDR DnsServerIP;

        public zl_u8 WorkMode;

        public zl_u16 LocalPort;

        public zl_u8 DestMode;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
        public char[] DestName;
        public zl_u16 DestPort;

        public zl_u8 BaudrateIndex;
        public zl_u8 Parity;
        public zl_u8 DataBits;
        public zl_u8 StopBits;
        public zl_u8 FlowControl;

        public zl_u16 MaxPacketLen;
        public zl_u8 MaxTimeGap;

        public zl_u8 AppProtocol;

        public zl_u8 ReconnectTime;

        public zl_u8 KeepAliveTime;

        public zl_u16 WebPort;

        public zl_u8 status;
        public IP_ADDR ResourceIP;
        public zl_u16 ResourcePort;

        public zl_u8 Ver;
        public zl_u8 FuncSel;
        public zl_u8 FuncSel2;
        public IP_ADDR UDPGroupIP;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
        public char[] DevID;
        public zl_u8 IO;
        public zl_u8 FuncEn;
        public zl_u8 ServerModeParamT;
    };
#pragma pack() 
    public static partial class ZLAN
    {

        [DllImport("ZLDevManage.dll", EntryPoint = "ZLDM_Init", CallingConvention = CallingConvention.StdCall)]
        public static extern zl_bool Init(zl_u16 ServerPort);
        [DllImport("ZLDevManage.dll", EntryPoint = "ZLDM_Exit", CallingConvention = CallingConvention.StdCall)]
        public static extern void Exit();
        [DllImport("ZLDevManage.dll", EntryPoint = "ZLDM_StartSearchDev", CallingConvention = CallingConvention.StdCall)]
        public static extern UInt16 StartSearchDev(ZLDevHandler[] hDev, zl_u16 hDevSize);
        [DllImport("ZLDevManage.dll", EntryPoint = "ZLDM_GetDevParam", CallingConvention = CallingConvention.StdCall)]
        public static extern zl_bool GetDevParam(ZLDevHandler h, ref SDevParam pParam);
        [DllImport("ZLDevManage.dll", EntryPoint = "ZLDM_SetDevParam", CallingConvention = CallingConvention.StdCall)]
        public static extern zl_bool SetDevParam(ZLDevHandler h, SDevParam pParam);
        [DllImport("ZLDevManage.dll", EntryPoint = "ZLDM_DevOpen", CallingConvention = CallingConvention.StdCall)]
        public static extern zl_bool DevOpen(ZLDevHandler h, UInt32 mode, UInt32 hWndCaller);
        [DllImport("ZLDevManage.dll", EntryPoint = "ZLDM_DevClose", CallingConvention = CallingConvention.StdCall)]
        public static extern zl_bool DevClose(ZLDevHandler h);
        [DllImport("ZLDevManage.dll", EntryPoint = "ZLDM_DevWrite", CallingConvention = CallingConvention.StdCall)]
        public static extern int DevWrite(ZLDevHandler h, char[] buf, int size);
        [DllImport("ZLDevManage.dll", EntryPoint = "ZLDM_DevRead", CallingConvention = CallingConvention.StdCall)]
        public static extern int DevRead(ZLDevHandler h, char[] buf, int size);


        [DllImport("ZLDevManage.dll", EntryPoint = "ZLDM_GetVer", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
        public static extern int GetVer();
        [DllImport("ZLDevManage.dll", EntryPoint = "ZLDM_AddManualDev", CallingConvention = CallingConvention.StdCall)]
        public static extern zl_bool AddManualDev(string ip_dns1, string ip_dns2, UInt16 port);
        [DllImport("ZLDevManage.dll", EntryPoint = "ZLDM_ClearManualDev", CallingConvention = CallingConvention.StdCall)]
        public static extern void ClearManualDev();

        [DllImport("ZLDevManage.dll", EntryPoint = "ZLDM_GetIO", CallingConvention = CallingConvention.StdCall)]
        public static extern Byte GetIO(Int32 h, char[] pIOStatus, char[] pFunc2Disable);
        [DllImport("ZLDevManage.dll", EntryPoint = "ZLDM_SetIO", CallingConvention = CallingConvention.StdCall)]
        public static extern Byte SetIO(Int32 h, Byte IOStatus, Byte Func2Disable);



        //typedef unsigned char       VTBYTE;



        //typedef char zl_u8; 



    }
    public static partial class ZLAN
    {
        public const int ID_LEN = 6;
        public const int WM_USER = 0x0400;
        public const int MAX_DEV_NAME_LEN = 10;//参数结构体中设备名称的最长长度
        public const int DNS_NAME_MAX_LEN = 30; //目的地址的最长长度  
        public const int WORK_MODE_SERVER = 0; //参数结构体中 WorkMode 取值 
        public const int WORK_MODE_CLIENT = 1;
        public const int IP_MODE_STATIC = 0; //参数结构体中 IPMode 的取值 
        public const int IP_MODE_DHCP = 1;
        public const int DEST_MODE_STATIC = 0; //参数结构体中 DestMode 的取值 
        public const int DEST_MODE_DYNAMIC = 1;
        public const int FLOW_C_NONE = 0; //参数结构体中 FlowControl 的取值 
        public const int FLOW_C_CTS_RTS = 1;
        public const int PARAM_PARITY_NONE = 0; //参数结构体中 Parity 的取值 
        public const int PARAM_PARITY_ODD = 1;
        public const int PARAM_PARITY_EVEN = 2;
        public const int PARAM_PARITY_MARK = 3;
        public const int PARAM_PARITY_SPACE = 4;
        public const int DATA_BITS_8 = 0; //参数结构体中 BaudrateIndex的取值 
        public const int DATA_BITS_7 = 1;
        public const int DATA_BITS_6 = 2;
        public const int DATA_BITS_5 = 3;
        public const int BANDURATE_1200 = 0;//参数结构体中 DataBits 的取值 
        public const int BANDURATE_2400 = 1;
        public const int BANDURATE_4800 = 2;
        public const int BANDURATE_7200 = 3;
        public const int BANDURATE_9600 = 4;
        public const int BANDURATE_14400 = 5;
        public const int BANDURATE_19200 = 6;
        public const int BANDURATE_28800 = 7;
        public const int BANDURATE_38400 = 8;
        public const int BANDURATE_57600 = 9;
        public const int BANDURATE_76800 = 10;
        public const int BANDURATE_115200 = 11;
        public const int APP_PRO_NONE = 0; //转化协议类型定义 
        public const int APP_PRO_MODBUS_RTU = 1;
        public const int MODBUS_TCP_SERVER_PORT = 502;
        public const int MODBUS_TCP_DATA_START = 6;
        public const int DEV_STATUS_CLOSED = 0;
        public const int DEV_STATUS_OPENED = 1;
        public const int ZLDM_HANDLER_ARRAY_MIN_SIZE = 256; //设备句柄数据的建议最小值  
        public const int ZLDM_FAST_SEND = 0;//快速发送模式 
        public const int ZLDM_BULK_SEND = 1; //大数据量发送模式
        public const int ZLDM_CALL_MESSAGE = 0x00;  
        public const int ZLDM_CALL_BACK = 0x02;  

        public const int WM_ZLDM_RECV = (WM_USER + 1920); //消息定义 
        public const int ZLDM_VER = 9;  //函数库版本号 

        public const int WM_WINDOWPOSCHANGED = 0x0047;
        public const int WM_WINDOWPOSCHANGING = 0x0046;
        public const int WM_NCMOUSEMOVE = 0xa0;
        public const int WM_NCLBUTTONDOWN = 0xA1;
        public const int WM_NCLBUTTONUP = 0xA2;
        public const int WM_NCLBUTTONDBLCLK = 0xA3;
        public const int WM_NCRBUTTONDOWN = 0xA4;
        public const int WM_NCRBUTTONUP = 0xA5;
        public const int WM_CAPTURECHANGED = 0x0215;
        public const int WM_EXITSIZEMOVE = 0x0232;
        public const int WM_ENTERSIZEMOVE = 0x0231;
        public const int WM_MOVE = 0x0003;
        public const int WM_MOVING = 0x0216;
        public const int WM_KILLFOCUS = 0x0008;
        public const int WM_SETFOCUS = 0x0007;
        public const int WM_ACTIVATE = 0x0006;
        public const int WM_NCHITTEST = 0x0084;

        public const int WA_INACTIVE = 0x0000;
    }
}